$(function () {
	console.log("baseURL::"+baseURL)
    new AjaxUpload('#upload', {
        action: baseURL + "sys/upload/imgUpload",
        name: 'imgFile',
        autoSubmit:true,
        responseType:"json",
        onComplete : function(file, r){
            if(r.code == 0){
                alert("图片上传成功！！");
                $("#bingimg").attr('src',r.url);
                vm.btCustomerBase.mainimg = r.url;
            }else{
                alert(r.msg);
            }
        }
    });
    new AjaxUpload('#uploadlogo', {
        action: baseURL + "sys/upload/imgUpload",
        name: 'imgFile',
        autoSubmit:true,
        responseType:"json",
        onComplete : function(file, r){
            if(r.code == 0){
                alert("图片上传成功！！");
                $("#logoimg").attr('src',r.url);
                vm.btCustomerBase.logo = r.url;
            }else{
                alert(r.msg);
            }
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		btCustomerBase: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			//vm.title = "新增";
			vm.btCustomerBase = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.btCustomerBase.id == null ? "sys/btcustomerbase/save" : "sys/btcustomerbase/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.btCustomerBase),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						//alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/btcustomerbase/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/btcustomerbase/info", function(r){
				if(r.code == 0)
                  vm.btCustomerBase = r.btCustomerBase;
				else
                    alert(r.msg);
            });
		},
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                page:page
            }).trigger("reloadGrid");
        }
	},
    mounted: function () {
        this.getInfo();
    }
});